#include <stack>
#include <iostream>
using std::stack;
using std::cout;
using std::endl;

namespace Code
{
class Queue
{
public:
	void push(int i)
	{
		m_s1.push(i);
	}

	// 空队列pop会出错
	int pop()
	{
		int ret;

		if (!m_s2.empty()) {
			ret = m_s2.top();
			m_s2.pop();
			return ret;
		}
		
		// 将s1中的元素pop出来push到s2中
		while (!m_s1.empty()) {
			m_s2.push(m_s1.top());
			m_s1.pop();
		}

		ret = m_s2.top();
		m_s2.pop();
		return ret;
	}

private:
	stack<int> m_s1;
	stack<int> m_s2;
};
}


int main()
{
	Code::Queue q;

	for (int i = 0; i < 10; ++i) {
		q.push(i);
	}

	for (int i = 0; i < 10; ++i) {
		cout << q.pop() << endl;
	}

	return 0;
}
